for (election2use in elections2use <- c("2012-GE", "2014-GE", "2016-GE", "2018-GE")) {
  
  election_date2use = election_dates[[election2use]] 
  
  row2add <- abl_files[[election2use]] %>%
    filter(received_type == "MA",
           !is.na(received_date)) %>%
    mutate(on_time = received_date <= !!election_date2use) %>%
    summarize(ballots = n(),
              on_time = sum(on_time)) %>%
    mutate(on_time_percent = 100 * on_time / ballots)
  
  if (match(election2use, elections2use) == 1) {
    fortable <- row2add
  }
  else {
    fortable <- rbind(fortable, row2add)
  }
}

fortable <- cbind(elections2use, fortable)
names(fortable) <- c("Election", "VBM ballots", "On-time", "On-time percent")
fortable$Election <- gsub("-", " ", fortable$Election)

table2use <- xtable(fortable,
                    caption = "VBM ballots cast in Maine general elections",
                    align = "llrrr",
                    digits = c(0,0,0,0,2),
                    label =  "tab:vbm_summary")

print.xtable(x = table2use, file = "/Users/herron/research/vbm-vulnerable-maine/tables/vbm-summary.tex", type = "latex", table.placement = "!ht", caption.placement = "top", include.colnames = TRUE, include.rownames = FALSE, format.args = list(big.mark = ","))
